<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{Layuimini/lib/layui-v2.6.3/css/layui.css}" href="Layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" th:href="@{Layuimini/lib/font-awesome-4.7.0/css/font-awesome.min.css}" media="all">
    <link rel="stylesheet" th:href="@{Layuimini/css/public.css}" href="Layuimini/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>

<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">网址名称</label>
        <div class="layui-input-block">
            <input type="text" name="superName" lay-verify="required" lay-reqtext="收藏网址名称不能为空"  value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">网址地址</label>
        <div class="layui-input-block">
            <input type="text" name="superUrl" lay-verify="required" lay-reqtext="网址地址不能为空"  value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label  class="layui-form-label">选择图标</label>
        <div class="layui-input-block">
            <input type="text" name="superIcon"   id="iconPicker1" value="fa-hand-o-up" lay-filter="iconPicker2" class="hide">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label required">网址类型</label>
        <div class="layui-input-block">
            <select name="superType" id="superType" lay-verify="required">
                <option value="">请选择网址类型</option>
                <option value="1">常用网址</option>
                <option value="2">工具网址</option>
                <option value="3">其他网址</option>
            </select>
        </div>

    </div>



    <div class="layui-form-item">
        <label class="layui-form-label">网址排序</label>
        <div class="layui-input-block">
            <input type="number"  name="sort"  value="0" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">网址描述</label>
        <div class="layui-input-block">
            <textarea name="superDesc" class="layui-textarea" ></textarea>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>

            <button class="layui-btn layui-btn-warm" id="resetBtn" type="reset">重置</button>
        </div>

    </div>
</div>
<script th:src="@{LightYear/js/jquery.min.js}" charset="utf-8"></script>
<script th:src="@{Layuimini/lib/layui-v2.6.3/layui.js}" charset="utf-8"></script>
<script th:src="@{Layuimini/js/lay-config.js}" charset="utf-8"></script>
<script>
    layui.use(['iconPickerFa','form','table'], function () {
        var iconPickerFa = layui.iconPickerFa,
            form = layui.form,
            layer = layui.layer,
            table = layui.table,
            $ = layui.$;

       var  prefix = "fa ";

        iconPickerFa.render({
            // 选择器，推荐使用input
            elem: '#iconPicker1',
            // fa 图标接口
            url: "Layuimini/lib/font-awesome-4.7.0/less/variables.less",
            // 是否开启搜索：true/false
            search: true,
            // 是否开启分页
            page: true,
            // 每页显示数量，默认12
            limit: 12,
            // 点击回调
            click: function (data) {
              //  console.log(data);
            },
            // 渲染成功后的回调
            success: function (d) {
             //   console.log(d);
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            data.field.superIcon = prefix + data.field.superIcon;
           // console.log(data);

            this.disabled=true;//防止按钮重复提交
            //保存操作
            $.ajax({
                url:"superUrlFavorite/saveSuperUrlFavorite",
                type:"POST",
                data:data.field,
                contentType: 'application/json; charset=UTF-8',
                async:false,
                dataType:'json',
                data:JSON.stringify(data.field),
                success:function(result){
                   // console.log(result);
                    layer.msg('添加成功！',{
                        time:2000
                    },function(){
                        window.parent.location.reload();  //刷新父页面
                    })
                }
            });
            return false;
        });


        $("#resetBtn").click(function () {
            layer.msg("重置成功！", {
                    time: 1000, //6s后自动关闭
                    icon:6,
                },function () {
                    window.location.reload();
                // $("input[name='superName']").val("");
                // $("input[name='superUrl']").val("");
                // $("input[name='sort']").val("0");
                // $("textarea[name='superDesc']").val("");

                }
            );
        })

    });
</script>
</body>
</html>